import * as d3 from 'd3';
import {geoAitoff} from "d3-geo-projection";
import {ProjectionEarth, ProjectionSky} from "@/utils/projection/projection";


class SphereEarth extends ProjectionEarth {

    _setProjection() {
        return d3.geoOrthographic();
    }

}


export class StaticSphereEarth extends SphereEarth {

    _initOptions() {
        this.options.drag = true;
        this.options.rotation = false;
        super._initOptions();
    }

}


export class DynamicSphereEarth extends SphereEarth {

    _initOptions() {
        this.options.rotate = [0, 0, -23.5];
        this.options.rotation = true;
        super._initOptions();
    }

}


class PlaneEarth extends ProjectionEarth {

    _setDefaultOpt() {
        super._setDefaultOpt();
        this.defaultOpt.scaleRatio = Math.PI * 1.25;
        // =================================================================
        this.defaultOpt.sun_moon = true;
        this.defaultOpt.switch_to_pos = 3;
        this.defaultOpt.sun_zone_radius = 90;
        // =================================================================
        this.defaultOpt.rotation = true;
        this.defaultOpt.rotationRatio = 360 / (24 * 60 * 60 * 1000);
        // =================================================================
        this.defaultOpt.zoom = true;
        this.defaultOpt.zoomScale = [0.5, 10];
        // =================================================================
        this.defaultOpt.drag = true;
        this.defaultOpt.dragRatio = 10;
    }

    _dragProjConf(deltX, deltY) {
        let proj = this.projection;
        proj = proj.rotate([
            proj.rotate()[0] + deltX * this.dragFactor[0] * this.increaseFactor[0],
            proj.rotate()[1],
            proj.rotate()[2]
        ]);
        return proj;
    }

}


export class NaturalEarth extends PlaneEarth {

    _setProjection() {
        return d3.geoNaturalEarth1();
    }

}


export class AitoffEarth extends PlaneEarth {

    _setProjection() {
        return geoAitoff();
    }

}


////////////////////////////////////////////////////////////////


export class SphereSky extends ProjectionSky {

    _setProjection() {
        return d3.geoOrthographic();
    }

}


export class DynamicSphereSky extends SphereSky {

    _initOptions() {
        this.options.rotation = true;
        this.options.rotationRatio = 360 / (60 * 60 * 24);
        this.options.rotationFrequency = 20;
        super._initOptions();
    }

}


export class PlaneSky extends ProjectionSky {

    _setDefaultOpt() {
        super._setDefaultOpt();
        this.defaultOpt.scaleRatio = Math.PI * 1.2;
        this.defaultOpt.drag = true;
        this.defaultOpt.rotation = false;
    }

}


export class AitofflSky extends PlaneSky {

    _setDefaultOpt() {
        super._setDefaultOpt();
        // this.defaultOpt.in_out = -1; // inside
        this.options.rotate = [-90, 0, 0];
        this.options.rotation = true;
        this.options.switch_to_pos = false;
    }

    _setProjection() {
        return geoAitoff();
    }

}

